//
//  main.c
//  字符串左旋查找
//
//  Created by 卜绎皓 on 2022/3/26.
//

#include <stdio.h>
#include <string.h>

void left(char* arr,int n,int len){
    n = n%len;
    int i = 0;
    for(i = 0;i < n;i++){
        char a = arr[0];
        int j = 0;
        for(j = 0;j < len -1;j++){
            arr[j] = arr[j+1];
        }
        arr[j] = a;
    }
}

void judge(char* arr1,char* arr2){
    int ret = strcmp(arr1, arr2);
    if(ret == 0){
        printf("相同");
    }
    else{
        printf("不同");
    }
}

int main()
{
    int n = 0;
    char arr1[] = "ABCD";
    char arr2[] = "CDAB";
    printf("左旋前字符串：%s\n",arr1);
    printf("对比字符串：%s\n",arr2);
    int len = strlen(arr1);
    printf("需要左旋字符数：");
    scanf("%d",&n);
    left(arr1,n,len);
    printf("左旋后字符：%s\n",arr1);
    judge(arr1,arr2);
    return 0;
}
